HandleOverlay:
	ld hl,0
	add hl,sp
	ex de,hl
	ld hl,saveSP
	ld (hl),e
	inc hl
	ld (hl),d
	ld sp,RAMEnd-2
	ld de,BackBuffer
	ld hl,LCDBuffer
	ld bc,768
	ldir			; copy the buffer to the backbuffer
	ld de,_
	call GetPointer	; loc in ix
	ld a,0	; xpos
	ld l,47	; ypos
	ld b,9	; height
	ld c,3	; width
	call LargeSpriteAND	; draw the mask
	ld de,++_
	call GetPointer
	ld a,0	; xpos
	ld l,47	; ypos
	ld b,9	; height
	ld c,3	; width
	call LargeSpriteOR	; draw the Sprite
	ld de,+++_
	call GetPointer	; loc in ix
	ld a,34	; xpos
	ld l,13	; ypos
	ld b,25	; height
	ld c,4	; width
	call LargeSpriteAND	; draw the mask
	ld de,++++_
	call GetPointer
	ld a,34	; xpos
	ld l,13	; ypos
	ld b,25	; height
	ld c,4	; width
	call LargeSpriteOR	; draw the Sprite
	ld a,(PanelEnabled)
	if(DISABLED)
		call z,DrawPanel
	call FastCopy
	call FlushKeys
SysMenuWaitLoop:
		call GetKey
		cp kUp
			jr z,__Sleep
		cp kDown
			jr z,__Boot
		cp kRight
			jr z,AppSwitchRight
		cp kLeft
			jp z,AppSwitchLeft
		cp kF1
			jp z,SysMenu
		in a,(04h)
		bit 3, a
			jr z,SysMenuWaitLoop	; wait until ON is released
SysMenuEnd:
	ld hl,BackBuffer
	ld de,LCDBuffer	; restore the buffer and backbuffer location
	ld bc,768
	ldir		; copy the backbuffer to the buffer
	call FastCopy	; display the old screen
	ld hl,(saveSP)
	ld sp,hl
	jp InterruptDone	; return to the check
__Sleep:
	call Sleep
	jp SysMenuEnd
__Boot:
	call ClearBuffer
	call FastCopy
	jp Boot
AppSwitchRight:
	
	jp SysMenuWaitLoop
AppSwitchLeft:
	
	jp SysMenuWaitLoop
SysMenu:
	ld hl,BackBuffer
	ld de,LCDBuffer	; restore the buffer and backbuffer location
	ld bc,768
	ldir		; copy the backbuffer to the buffer
	rectangle(24,20,72,39,0FFh)
	rectangle(25,19,71,40,0FFh)
	rectangle(25,20,71,39,0)
	ld de,++++++_
	call GetPointer
	ex de,hl
	ld a,15
	ld (TextY),a
	call resMT
	call DrawWrappedString
	call resMT
	call DrawWrappedString
	call resMT
	call DrawWrappedString
	xor a
	ld (MenuTmp),a
SysMenuLoop:
	ld DE,+++++_
	call GetPointer
	ld a,(MenuTmp)
	ld e,22
	ld d,a
	add a,a
	add a,d
	add a,a
	add a,e
	ld e,a
	ld d,22
	ld b,3
	call PutSpriteOR
	call FastCopy
	ld DE,+++++_
	call GetPointer
	ld a,(MenuTmp)
	ld e,22
	ld d,a
	add a,a
	add a,d
	add a,a
	add a,e
	ld e,a
	ld d,22
	ld b,3
	call PutSpriteXOR
	call FlushKeys
	call WaitKey
	cp kUp
		jr z,SysMenuUp
	cp kDown
		jr z,SysMenuDown
	cp kClear
		jp z,SysMenuEnd
	cp k2nd
		jr nz,SysMenuLoop
	ld a,(MenuTmp)
	or a
;		jr z,AppSysMenu
	cp 1
;		jr z,SettingsSysMenu
	xor a
	jp SysMenuEnd
SysMenuUp:
	ld a,(MenuTmp)
	or a
		jr z,SysMenuLoop
	dec a
	ld (MenuTmp),a
	jr SysMenuLoop
SysMenuDown:
	ld a,(MenuTmp)
	cp 2
		jr z,SysMenuLoop
	inc a
	ld (MenuTmp),a
	jr SysMenuLoop
resMT:
	call Newline
	ld a,30
	ld (TextX),a
	ret
_	db "usr/share/system/menu_mask.bif",0
_	db "usr/share/system/menu.bif",0
_	db "usr/share/system/overlay_mask.bif",0
_	db "usr/share/system/overlay.bif",0
_	db "usr/share/system/menu_pointer.bif",0
_	db "usr/share/system/menu.locale",0
